package com.dzf.controller;

import com.dzf.entity.LargeFile;
import com.dzf.entity.RespJson;
import com.dzf.entity.User;
import com.dzf.service.LargeFileService;
import com.dzf.service.UserService;
import org.omg.PortableInterceptor.USER_EXCEPTION;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/api/adm/user")
public class AdmUserController {
    @Autowired
    UserService userService;


    @RequestMapping("/addAdm")
    public RespJson addAdm(User user,@RequestParam(value = "pic",required = false) MultipartFile pic){

        userService.addAdm(user,pic);
        return RespJson.pack(200,"添加管理员成功....",null);
    }

    @RequestMapping("findAll/{start}/{num}")
    public RespJson findAll(@PathVariable("start")int start,@PathVariable("num")int num)
    {
        Map<String, Object> map = new HashMap<>();
        map.put("start", (start*num)-num);
        map.put("num",num);
        List<User> users = userService.findAll(map);
        Map<String, Object> map1 = new HashMap<>();
        map1.put("total",userService.findTotal());
        map1.put("users",users);
        return RespJson.pack(200,"OK",map1);
    }

    @RequestMapping("/resetPwd/{uid}")
    public RespJson resetPwd(@PathVariable("uid")int uid)
    {
        userService.resetPwd(uid);
        return RespJson.pack(200,"密码已重置为111111",null);
    }

    @RequestMapping("close/{uid}")
    public RespJson close(@PathVariable("uid")int uid){
        userService.close(uid);
        return RespJson.pack(200,"用户已被冻结",null);
    }

    @RequestMapping("findById/{uid}")
    public RespJson findById(@PathVariable("uid")int uid){
        return RespJson.pack(200,"",userService.findById(uid));
    }

}
